﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PusherRESTDotNet;

namespace WebApplication7
{
    public partial class Test : System.Web.UI.Page
    {
        private int activeIndex = 0;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (HidenUserName.Value.Length == 0)
            {
                String name = Convert.ToString(Session["username"]);
                this.GamePannel1.setPlayerInfo(name, 0f, 0, "~/" + name + ".png");
                this.GamePannel1.addPlayer("player1", 0f, 0);
                this.GamePannel1.addPlayer("player2", 0f, 0);
                this.GamePannel1.addPlayer("player3", 0f, 0);
                this.GamePannel1.addPlayer("player4", 0f, 0);
            }
            else
            {
                this.GamePannel1.addPlayer("player1", 0f, 0);
                this.GamePannel1.addPlayer("player2", 0f, 0);
                this.GamePannel1.addPlayer("player3", 0f, 0);
                this.GamePannel1.addPlayer("player4", 0f, 0);
                ServiceNimic sn = ServiceNimic.getInstance();
                int actInd = sn.getActivePlayerIndex();
                for (int i = 0; i <= activeIndex; i++)
                {
                    this.GamePannel1.activateNext();
                }
            }
        }

        protected void Button1_Click1(object sender, EventArgs e)
        {
            ServiceNimic sn = ServiceNimic.getInstance();
            // Ovde bi trebalo da ide samo id na player izmeni za ponatamu
            int x = 0;

            switch (HidenUserName.Value) 
            {
                case "player1" : 
                            x = 0;
                            break;
                case "player2" : 
                            x = 1;
                            break;
                case "player3": 
                            x = 2;
                            break;
                case "player4" :
                            x = 3;
                            break;
            }
            ServiceDice.Service1 serviceDice = new ServiceDice.Service1();

            int y = Convert.ToInt16(serviceDice.RndNumber());
            sn.iRolledTheDice(x, y);
            sn.nextActivePlayerIndex();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {

        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            ServiceNimic sn = ServiceNimic.getInstance();
            sn.nextActivePlayerIndex();
        }

    }
}